package com.bountytask.controller;

import com.alibaba.fastjson.JSONObject;
import com.bountytask.entity.UserInfo;
import com.bountytask.service.UserService;
import com.bountytask.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    //更新用户数据
    @PutMapping("/user/update")
    public JSONObject updateUserInfo(@RequestBody UserInfo user){
        return userService.updateUserInfo(user);
    }

    @GetMapping("/user/get/{id}")
    public JSONObject getUserById(@PathVariable long id){
        JSONObject resultJson = new JSONObject(true);
        UserInfo user = userService.getUserById(id);
        if (user==null){
            resultJson.put("code",400);
            resultJson.put("message","失败");
            return resultJson;
        }
        resultJson.put("code",200);
        resultJson.put("message","成功");
        resultJson.put("data",user);
        return resultJson;
    }
}
